package java8stream;

import java.util.ArrayList;
import java.util.List;
import java.util.Optional;
import java.util.stream.Stream;

/**
 * Created by ZhuQianli on 2018/1/16.
 */
public class StreamReduce {
    public static void main(String[] args) {
        List<Integer> list = new ArrayList<>();
        for (int i = 0; i < 100; i++, list.add(i));

        // identity:起始的值（可有可无）
        Integer reduce = list.stream().reduce(2, Integer::sum);
        Optional.ofNullable(reduce).ifPresent(System.out::println);


        Optional<String> reduce1 = Stream.of("a", "b", "c", "d", "E", "F", "g").filter(e -> e.compareTo("Z") > 0).reduce(String::concat);
        reduce1.ifPresent(System.out::println);

    }
}
